<template>
	<view class="outside">
		<view class="money-card">
			<view class="">收款金额</view>
			<view class="money">
				<text class="first">积分</text>
				<view class="second" @tap='openKeyboard()'>{{money==''?0:money}}</view>
			</view>
			<view class="line"></view>

		</view>
		<!-- <button type="default" @tap='op()'>ddd</button> -->
		<cu-keyboard ref="cukeyboard" @change="change" @confirm="payBtn" @hide="hide"></cu-keyboard>
		<!-- <view class="btn-box">
			<view class="btn" @tap='payBtn'>收款</view>
		</view> -->

	</view>
</template>

<script>
	export default {
		data() {
			return {
				money: '',
				md5: this.$store.state.md5,
				type: this.$store.state.type,

			}
		},
		onLoad(parameter) {
			let _this = this
			setTimeout(function() {
				_this.open()
			}, 100);
		},
		onShow() {
			
		},
		methods: {
			change(e) {
				this.money = e;
			},
			open() {
				console.log("打开键盘");
				this.$refs.cukeyboard.open();
			},

			hide() {
				console.log("关闭键盘")
			},
			openKeyboard() {
				this.$refs.cukeyboard.open();
			},
			payBtn() {
				if(this.money.indexOf(".")>=0 && this.money.split('.')[1].length>2){
					uni.showToast({
						title: '金额不正确',
						duration: 1500,
						icon: "error"
					});
				}
				if (this.type == 1) {
					this.$api.shop_scan_QR_codes({
						md5: this.md5,
						accumulatePoints: this.money
					}, this.pageNum, this.pageSize).then((res) => {
						if (res.data.success) {
							this.ScanAudio(res.data.dataMap); //播放语音
							uni.showToast({
								title: '收款成功',
								duration: 1500,
								icon: "success"
							});
							setTimeout((res) => {
								this.money = ''
								uni.navigateBack(1)
							}, 1500);

						} else {
							uni.showToast({
								title: res.data.message,
								duration: 1000,
								icon: "none"
							});
						}

					})

				} else if (this.type == 2) {
					console.log(this.md5)
					this.$api.member_deduct_money({
						money: this.money,
						memberNumber: this.md5
					}).then((res) => {
						if (res.data.success) {
							this.ScanAudio(res.data.dataMap); //播放语音
							uni.showToast({
								title: '收款成功',
								duration: 1500,
								icon: "success"
							});
							setTimeout((res) => {
								this.money = ''
								uni.navigateBack(1)
							}, 1500);

						} else {
							uni.showToast({
								title: res.data.message,
								duration: 1000,
								icon: "none"
							});
						}

					})

				}

			},
			press(value) {
				if (value == '.') {
					if (this.money.indexOf('.') > 0) {

					} else {
						this.money = this.money + value

					}
				} else if (value == 'x') {
					// this.money.

				} else {
					//判断小数的几位
					this.money = this.money + value
				}



			},

		}
	}
</script>

<style lang="less" scoped>
	page {
		height: 100;
		background-color: #F8f8f8;
	}

	.btn-box {
		width: 690rpx;
		height: 100rpx;
		background: #FF5551;
		border-radius: 16rpx;
		margin: 0 auto;
		margin-top: 40rpx;

		.btn {
			font-size: 32rpx;
			font-weight: 500;
			color: #FFFFFF;
			text-align: center;
			line-height: 100rpx;
		}
	}

	.keyboard {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-around;
		margin-top: 20rpx;

		.number {
			width: 216rpx;
			height: 120rpx;
			background: #FFFFFF;
			border-radius: 16rpx;
			margin-top: 20rpx;
			text-align: center;
			line-height: 120rpx;
			font-size: 88rpx;
			color: #333333;
			font-weight: 400;
		}
	}

	.money-card {
		height: 400rpx;
		width: 750rpx;
		background-color: #FFFFFF;

		.line {
			height: 2rpx;
			width: 90%;
			background-color: #eee;
			margin: 0 auto;
		}

		.money {
			padding: 10rpx 50rpx;
			display: flex;
			align-items: center;
			height: 80px;

			.first {
				font-size: 36rpx;
				font-weight: bold;
				color: #999999;
				width: 100rpx;
			}

			.second {
				width: 650rpx;
				font-size: 68rpx;
				font-weight: bold;
				color: #333333;
				margin-left: 10rpx;
			}
		}

		view:nth-child(1) {
			padding: 20rpx 50rpx;
			font-size: 32rpx;
			color: #333333;

		}
	}
</style>
